{extend name="admin/base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<script src="ADMIN_JS/material_managedialog.js"></script>
<style>
.ns-main{margin-top:0px;}
.time-unit{position: relative;top: -2px;left: -4px;}
.selectric-items li{overflow: inherit;}
.selectric-items .selectric-scroll::-webkit-scrollbar,.selectric-items .selectric-scroll::-webkit-scrollbar{width: 2px;height: 2px;}
.selectric-items .selectric-scroll::-webkit-scrollbar-track,.selectric-items .selectric-scroll::-webkit-scrollbar-track{background-color: #fff;}
.selectric-items .selectric-scroll::-webkit-scrollbar-thumb,.selectric-items .selectric-scroll::-webkit-scrollbar-thumb{background-color: #ddd;}
.time-slot-item{padding:0 15px 0 10px;border:1px solid #ddd;margin-bottom: 10px;margin-right:10px;display: inline-block;cursor: pointer;position: relative;user-select: none;}
.time-slot-item .del{position: absolute;right: 0;top:0;display: inline-block;width: 12px;height: 12px;background: #f5f5f5;color: #666;text-align: center;line-height: 12px;font-style: normal;}
.time-slot-item.selected{border-color: #0059d6}
</style>
{/block}
{block name="main"}
<div class="set-style">
	<!-- 模块一 -->
	<h4><span></span>基础设置</h4>
	<dl>
		<dt>自动收货时间：</dt>
		<dd>
			<input id="order_auto_delinery" type="number" min="0.00" step="1.00" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')" value="{$shopSet['order_auto_delinery']}" class="input-common harf"/><em class="unit">天</em>
			<p class="hint">订单多长时间后自动收货，单位为/天(注：若为0，则订单不会自动收货)</p>
		</dd>
	</dl>
	<dl>
		<dt>订单自动关闭时间：</dt>
		<dd>
			<input id="order_buy_close_time" type="number" min="0.00" step="1.00" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')" value="{$shopSet['order_buy_close_time']}" class="input-common harf" /><em class="unit">分钟</em>
			<p class="hint">订单开始后多长时间未付款自动关闭，单位为/分钟(注：不填写或0订单将不会自动关闭)</p>
		</dd>
	</dl>
	<dl>
		<dt>是否开启在线支付：</dt>
		<dd>
			<div class="controls">
				<p>
					<input id="order_online_pay" type="checkbox"  class="checkbox" {if condition="$shopSet['order_online_pay'] eq 1"}checked{/if}/>
				</p>
			</div>
			<p class="hint">是否启用在线支付功能</p>
		</dd>
	</dl>
	<dl>
		<dt>是否开启余额支付：</dt>
		<dd>
			<div class="controls">
				<p>
					<input id="order_balance_pay" type="checkbox"  class="checkbox" {if condition="$shopSet['order_balance_pay'] eq 1"}checked{/if}/>
				</p>
			</div>
			<p class="hint">是否启用余额支付功能</p>
		</dd>
	</dl>
	<dl>
		<dt>是否开启货到付款：</dt>
		<dd>
			<div class="controls">
				<p>
					<input id="order_delivery_pay" type="checkbox"  class="checkbox" {if condition="$shopSet['order_delivery_pay'] eq 1"}checked{/if}/>
				</p>
			</div>
			<p class="hint">是否开启货到付款功能</p>
		</dd>
	</dl>
	<dl>
		<dt>订单完成时间：</dt>
		<dd>
			<p style="height: 30px;">
				<select id="order_delivery_complete_time" class="select-common">
					<option value="0" {if $shopSet['order_delivery_complete_time'] eq 0}selected{/if}>立即</option>
					<option value="1" {if $shopSet['order_delivery_complete_time'] eq 1}selected{/if}>1天</option>
					<option value="2" {if $shopSet['order_delivery_complete_time'] eq 2}selected{/if}>2天</option>
					<option value="3" {if $shopSet['order_delivery_complete_time'] eq 3}selected{/if}>3天</option>
					<option value="4" {if $shopSet['order_delivery_complete_time'] eq 4}selected{/if}>4天</option>
					<option value="5" {if $shopSet['order_delivery_complete_time'] eq 5}selected{/if}>5天</option>
					<option value="6" {if $shopSet['order_delivery_complete_time'] eq 6}selected{/if}>6天</option>
					<option value="7" {if $shopSet['order_delivery_complete_time'] eq 7}selected{/if}>7天</option>
				</select>
			</p>
			<input type="hidden" id="closeday" value="{$shopSet['order_delivery_complete_time']}">
			<p class="hint">收货后，多少时间订单自动完成，单位为/天</p>
		</dd>
	</dl>
	<dl>
		<dt>购物返积分设置：</dt>
		<dd>
			<p style="height: 30px;">
				<select id="shopping_back_points" class="select-common">
					<option value="1" {if condition="$shopSet['shopping_back_points'] eq 1"}selected{/if}>订单已完成</option>
					<option value="2" {if condition="$shopSet['shopping_back_points'] eq 2"}selected{/if}>已收货</option>
					<option value="3" {if condition="$shopSet['shopping_back_points'] eq 3"}selected{/if}>支付完成</option>
				</select>
			</p>
			<p class="hint">在什么时间将购物返积分添加到会员账户</p>
		</dd>
	</dl>	
	<dl>
		<dt>是否显示购买记录：</dt>
		<dd>
			<div class="controls">
				<p>
					<input id="order_show_buy_record" type="checkbox"  class="checkbox" {if condition="$shopSet['order_show_buy_record'] eq 1"}checked{/if}/>
				</p>
			</div>
			<p class="hint">前台页面是否显示购买记录(本功能暂时未启用)</p>
		</dd>
	</dl>
	<dl>
		<dt>系统默认评价设置：</dt>
		<dd>
			<div class="controls">
				<input type="number" class="input-common harf" value="{$shopSet['system_default_evaluate']['day']}" id="evaluate_day" min="0"><em class="unit">天</em>
			</div>
			<p class="hint">订单完成达到设置天数后，用户仍未进行评价，则系统进行默认评价</p>
		</dd>
	</dl>
	<dl>
		<dt>售后设置：</dt>
		<dd>
			<div class="controls">
				<input type="number" class="input-common harf" value="{$shopSet['shouhou_day_number']}" id="shouhoudate" min="0"><em class="unit">天</em>
			</div>
			<p class="hint">订单完成多少天之内可以售后</p>
		</dd>
	</dl>
	<dl>
		<dt>默认评价语：</dt>
		<dd>
			<div class="controls">
				<textarea class="textarea-common" id="evaluate">{$shopSet['system_default_evaluate']['evaluate']}</textarea>
			</div>
		</dd>
	</dl>
	<!-- 模块二 -->
	<h4><span></span>配送设置</h4>
	<dl style="{if condition="addon_is_exit('NsPickup') != 1"} display: none{/if}">
		<dt>是否开启买家自提：</dt>
		<dd>
			<div class="controls">
				<p>
					<input id="buyer_self_lifting" type="checkbox"  class="checkbox" {if condition="$shopSet['buyer_self_lifting'] eq 1"}checked{/if}/>
				</p>
			</div>
			<p class="hint">是否启用买家自提</p>
		</dd>
	</dl>
	<dl>
		<dt>是否开启物流配送：</dt>
		<dd>
			<div class="controls">
				<p>
					<input id="seller_dispatching" type="checkbox"  class="checkbox" {if condition="$shopSet['seller_dispatching'] eq 1"}checked{/if}/>
				</p>
			</div>
			<p class="hint">是否启用物流配送</p>
		</dd>
	</dl>
	
	
	<dl style="{if condition="addon_is_exit('NsO2o') != 1"} display: none{/if}">
		<dt>是否开启本地配送：</dt>
		<dd>
			<div class="controls">
				<p>
					<input id="is_open_o2o" type="checkbox"  class="checkbox" {if condition="$shopSet['is_open_o2o'] eq 1"}checked{/if}/>
				</p>
			</div>
			<p class="hint">是否启用本地配送</p>
		</dd>
	</dl>	
	
	
	<dl>
		<dt>是否允许选择物流：</dt>
		<dd>
			<div class="controls">
				<p>
					<input id="is_logistics" type="checkbox"  class="checkbox" {if condition="$shopSet['is_logistics'] eq 1"}checked{/if}/>
				</p>
			</div>
			<p class="hint">前台模板中,是否允许用户选择物流</p>
		</dd>
	</dl>
	
	<dl>
		<dt>开启指定配送时间：</dt>
		<dd>
			<div class="controls">
				<p>
					<input id="order_designated_delivery_time" type="checkbox"  class="checkbox" {if condition="$shopSet['order_designated_delivery_time'] eq 1"}checked{/if}/>
				</p>
			</div>
			<p class="hint">是否开启指定配送时间</p>
		</dd>
	</dl>

	<dl>
		<dt>设定配送时间段：</dt>
		<dd>
			<div class="time-slot">
				{if !empty($shopSet['time_slot'])}
					{foreach name="$shopSet['time_slot']" item="vo"}
						<span start="{$vo.start}" end="{$vo.end}" class="time-slot-item">{$vo.start}:00-{$vo.end}:00<i class="del" onclick="delTimeSlotItem(this)">×</i></span>
					{/foreach}
				{/if}
			</div>
			<div class="controls">
				<p>
					<select class="select-common short start">
						<option value="00">00</option>
						<option value="01">01</option>
						<option value="02">02</option>
						<option value="03">03</option>
						<option value="04">04</option>
						<option value="05">05</option>
						<option value="06">06</option>
						<option value="07">07</option>
						<option value="08">08</option>
						<option value="09">09</option>
						<option value="10">10</option>
						<option value="11">11</option>
						<option value="12">12</option>
						<option value="13">13</option>
						<option value="14">14</option>
						<option value="15">15</option>
						<option value="16">16</option>
						<option value="17">17</option>
						<option value="18">18</option>
						<option value="19">19</option>
						<option value="20">20</option>
						<option value="21">21</option>
						<option value="22">22</option>
						<option value="23">23</option>
					</select>
					<em class="unit time-unit">：00</em>
					<span>-</span>
					<select class="select-common short end">
						<option value="00">00</option>
						<option value="01">01</option>
						<option value="02">02</option>
						<option value="03">03</option>
						<option value="04">04</option>
						<option value="05">05</option>
						<option value="06">06</option>
						<option value="07">07</option>
						<option value="08">08</option>
						<option value="09">09</option>
						<option value="10">10</option>
						<option value="11">11</option>
						<option value="12">12</option>
						<option value="13">13</option>
						<option value="14">14</option>
						<option value="15">15</option>
						<option value="16">16</option>
						<option value="17">17</option>
						<option value="18">18</option>
						<option value="19">19</option>
						<option value="20">20</option>
						<option value="21">21</option>
						<option value="22">22</option>
						<option value="23">23</option>
					</select>
					<em class="unit time-unit">：00</em>
					<button class="btn-common" style="top: -2px;position: relative;" onclick="addTimeSlot(this);">添加</button>
				</p>
			</div>
			<p class="hint">商家设定配送时间段</p>
		</dd>
	</dl>
	
	<!-- 模块三 -->
	<h4><span></span>发票设置</h4>
	<dl>
		<dt>是否开启发票：</dt>
		<dd>
			<div class="controls">
				<p>
					<input id="invoice" type="checkbox"  class="checkbox" {if condition="$shopSet['order_invoice_type'] eq 1"}checked{/if}/>
				</p>
			</div>
			<p class="hint">是否开启发票功能</p>
		</dd>
	</dl>
	<dl>
		<dt>发票税率：</dt>
		<dd>
			<input id="order_invoice_tax" type="number" min="0.00" step="0.01" value="{$shopSet['order_invoice_tax']}" class="input-common harf" /><em class="unit">%</em>
			<p class="hint">设置开发票的税率，单位为%</p>
		</dd>
	</dl>
	<dl>
		<dt>发票内容：</dt>
		<dd>
			<textarea rows="2" id="order_invoice_content" class="textarea-common" maxlength="50">{$shopSet['order_invoice_content']}</textarea>
			<p class="hint">客户要求开发票时可以选择的内容，逗号分格代表一个选项，例如：办公用品,明细</p>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd><button class="btn-common btn-big" onclick="setConfigAjax();">保存</button></dd>
	</dl>
</div>
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>
var validation = true;//验证余额输入
$("#order_invoice_tax").live("keyup",function(){
	var reg = /^\d+(.{0,1})(\d{0,2})$/;
	if(!reg.test($(this).val())){
		showTip("请输入大于0的数字，并且保留两位小数","warning");
		validation = false;
	}else{
		validation = true;
	}
});

function setConfigAjax(){
	var order_delivery_complete_time = $('#order_delivery_complete_time').val();
	var order_buy_close_time = $('#order_buy_close_time').val();
	var order_auto_delinery = $("#order_auto_delinery").val();
	
	var order_invoice_tax = $("#order_invoice_tax").val();
	var order_invoice_content = $("#order_invoice_content").val();
	var shopping_back_points = $("#shopping_back_points").val();
	var invoice = $("#invoice").prop('checked') ? 1 : 0 ;
	var order_balance_pay = $("#order_balance_pay").prop('checked') ? 1 : 0 ;
	var order_show_buy_record = $("#order_show_buy_record").prop('checked') ? 1 : 0 ;
	var buyer_self_lifting = $("#buyer_self_lifting").prop('checked') ? 1 : 0 ;
	var seller_dispatching = $("#seller_dispatching").prop('checked') ? 1 : 0 ;
	var is_open_o2o = $("#is_open_o2o").prop('checked') ? 1 : 0 ;
	var is_logistics = $("#is_logistics").prop('checked') ? 1 : 0 ;
	var is_open_virtual_goods = 1; // $("#is_open_virtual_goods").prop('checked') ? 1 : 0 ;//是否开启虚拟商品
	var order_designated_delivery_time = $("#order_designated_delivery_time").prop('checked') ? 1 : 0 ;//是否开启指定配送时间
	var order_delivery_pay = $("#order_delivery_pay").prop('checked') ? 1 : 0 ;
	var order_online_pay = $("#order_online_pay").prop('checked') ? 1 : 0 ;
	var time_slot_arr = [];
	$(".time-slot .time-slot-item").each(function(){
		var time_slot = {
			'start': $(this).attr('start'),
			'end': $(this).attr('end')
		};
		time_slot_arr.push(time_slot);
	})
	if(invoice == 1){
		if(order_invoice_content == ""){
			showTip("开启发票，发票内容不能为空","warning");
			return false
		}
	}	
	var evaluate_day = $("#evaluate_day").val();
	var shouhoudate = $("#shouhoudate").val();
	var evaluate = $("#evaluate").val();
	if(evaluate_day > 0 && evaluate == ""){
		showTip("请设置系统默认评价语","warning");
		return;
	}

	if(validation){
		$.ajax({
			type:"post",
			url : "{:__URL('ADMIN_MAIN/config/shopset')}",
			data : {
				"order_delivery_complete_time" : order_delivery_complete_time,
				"order_buy_close_time":order_buy_close_time,
				"order_balance_pay" : order_balance_pay,
				"order_delivery_pay" : order_delivery_pay,
				"order_auto_delinery" : order_auto_delinery,
				"order_show_buy_record" : order_show_buy_record,
				"buyer_self_lifting" : buyer_self_lifting,
				"seller_dispatching" : seller_dispatching,
				"is_open_o2o" : is_open_o2o,
				"is_logistics" : is_logistics,
				"order_invoice_tax" : order_invoice_tax,
				"order_invoice_content" : order_invoice_content,
				"shopping_back_points" : shopping_back_points,
				"is_open_virtual_goods" : is_open_virtual_goods,
				"order_designated_delivery_time" : order_designated_delivery_time,
				"time_slot" : JSON.stringify(time_slot_arr),
				"evaluate_day" : evaluate_day,
				"evaluate" : evaluate,
				"shouhoudate" : shouhoudate,
				"order_online_pay" : order_online_pay,
				"invoice" : invoice
			},
			success : function(data){
				if(data['code'] > 0){
					showTip(data["message"],"success");
					location.href="{:__URL('ADMIN_MAIN/config/shopset')}";
				}else{
					showTip(data["message"],"error");
				}
			}
		});
	}else{
		showTip("请输入大于0的数字，并且保留两位小数","warning");
	}
}

$(".time-slot .time-slot-item").live('click', function(){
	var start = $(this).attr("start"),
	    end = $(this).attr("end");
   	initTimeSelect(start, end);
	$(this).addClass('selected').siblings().removeClass('selected');
});

function addTimeSlot(obj){
	var start = $(obj).parents("dd").find(".start").val(),
		end = $(obj).parents("dd").find(".end").val(),
		html = $(".time-slot").html();
		if($(".time-slot .time-slot-item.selected").length > 0){
			$(".time-slot .time-slot-item.selected").attr({'start':start, 'end':end}).text(start + ':00-' + end + ':00').removeClass('selected');
			initTimeSelect('00', '00')
		}else{
			html += '<span start="' + start + '" end="' + end + '" class="time-slot-item">' + start + ':00-' + end + ':00<i class="del" onclick="delTimeSlotItem(this)">×</i></span>';
			$(".time-slot").html(html);
			initTimeSelect('00', '00')
		}
}

function delTimeSlotItem(obj){
	$(obj).parent('span').remove();
	initTimeSelect('00', '00')
}

function initTimeSelect(start, end){
	$(".start option[value='" + start + "']").attr('selected', true);
   	$(".end option[value='" + end + "']").attr('selected', true);
   	$(".start,.end").selectric()
}
</script>
{/block}